// createRouter：创建router实例对象
// createWebHistory：创建history模式的路由
// 有history模式，hash模式

import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/Login/index.vue'
import Layout from '@/views/Layout/index.vue'
import Home from '@/views/Home/index.vue'
import Category from '@/views/Category/index.vue'
import Appdownload from '@/views/Appdownload/index.vue'
import Activity from '@/views/Activity/index.vue'
import Member from '@/views/Member/index.vue'
import UserInfo from '@/views/Member/components/UserInfo.vue'
import UserOrder from '@/views/Member/components/UserOrder.vue'
import LongRent from '@/views/LongRent/index.vue'
import Register from '@/views/Register/index.vue'
import ActivityDetails from '@/views/Activity/components/ActivityDetails.vue'



const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  // “routes”：path和component对应关系的位置
  routes: [
    {
      // 一级路由：整体内容切换
      path: '/',
      component: Layout,
      // 二级路由：在一级内容里切换
      children: [
        {
          // 默认二级路由，当访问一级路由时，自动渲染
          path: '',
          component: Home
        },
        {
          path: 'category/:id',
          component: Category
        },
        {
          path: 'appdownload',
          component: Appdownload
        },
        {
          path: 'activity',
          component: Activity
        },
        {
          path: '/activitydetails/:activityId',
          name: 'activitydetails',
          component: ActivityDetails
        },
        {
          path: 'member',
          component: Member,
          children: [

            {
              path: '',
              component: UserInfo
            },
            {
              path: 'order',
              component: UserOrder
            }
          ]
        },
        {
          path: 'longrent',
          component: LongRent
        }
      ]
    },
    {
      path: '/login',
      component: Login
    },
    {
      path: '/register',
      component: Register
    },
    // {
    //   path: '/detail/:id',
    //   component: Detail
    // },

  ],
  scrollBehavior(to, from, savedPosition) {
    // 如果存在 savedPosition，则恢复滚动位置
    if (savedPosition) {
      return savedPosition
    } else {
      // 否则，滚动到目标页面的顶部
      return { top: 0 }
    }
  }
})

export default router